package com.smallprogram.www.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smallprogram.www.comm.ServiceCode;
import com.smallprogram.www.entity.ResultEntity;
import com.smallprogram.www.model.Goods;
import com.smallprogram.www.service.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author hj
 * @since 2020-10-07
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    private static final Logger log = LoggerFactory.getLogger(GoodsController.class);

    @Autowired
    private GoodsService goodsService;
    @GetMapping("/goods")
    public ResultEntity<Object> ordered(){
        Wrapper<Goods> queryWrapper = new QueryWrapper(null);
        ResultEntity<Object> resultEntity =
                new ResultEntity<Object>(ServiceCode.SEUCCESS.getCode(),ServiceCode.SEUCCESS.getMessage(),goodsService.list(queryWrapper));
        return resultEntity;
    }
    @PostMapping("/goods")
    public ResultEntity save(@RequestBody Goods goods){
        boolean bool = goodsService.save(goods);
        if(bool){
            return  new ResultEntity(ServiceCode.SEUCCESS.getCode(),ServiceCode.SEUCCESS.getMessage());
        }else {
            return new ResultEntity(ServiceCode.FAIL.getCode(),ServiceCode.FAIL.getMessage());
        }
    }

}

